import { useAppStore } from "./store/user";
import router from "./router/index";

const PATHS = ["/order", "/shopping", "/settlement", "/collect"];
router.beforeEach((to, from, next) => {
  const userStore = useAppStore();
  if (userStore.user_id) {
    //已经登录
    next();
  } else {
    //未登录
    //判断是否去权限页面
    console.log(PATHS.includes(to.path));
    if (PATHS.includes(to.path)) {
      //跳转到登录页
      next(`/login?redirect=${to.path}`);
    } else {
      //不是去权限页面直接放行
      next();
    }
  }
});
